var getCookie = readCookie("user")

$(function() {
	if (getCookie != "") {
		getUcount()
		setLogin()
		getUserName()
	}

})

function setLogin() {
	if (getCookie != null) {
		$(".zhuce").html("欢迎光临本店！<a href='user_info.html' class='red'>" + getUserName() +
			"</a> 新用户<a href='registered.html' class='red'>[免费注册]</a>")
	} else {
		$(".zhuce").html(
			"欢迎光临本店！<a href='login.htm' class='red'>[请登录]</a> 新用户<a href='registered.html' class='red'>[免费注册]</a>")
	}

}

function getUserName() {
	var uName = ""
	$.ajax({
		url: "http://localhost:8080/user/login",
		type: "post",
		data: {
			"id": getCookie
		},
		async: false,
		dataType: "json",
		success: function(data) {
			if(data.status==0){
				location.href="login.htm"
			}
			uName = data.data.uName

		}
	})
	return uName
}

function getUcount() {

	$.ajax({
		url: "http://localhost:8080/shopcar/userSum",
		type: "get",
		data: {
			"uId": getCookie
		},
		async: false,
		dataType: "json",
		success: function(data) {

			$(".s_cart").html("<em></em><a href='shopping_cart.html'>我的购物车</a> <i class='ci-right'>&gt;</i><i class='ci-count' id='shopping-amount'>"+data.data+"</i>")
			$(".good_cart").html(data.data)
			$("#count").html(data.data)
		}
	})
}
